package com.music.activity.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.anmusic.application.R;
import com.music.model.FilGridItem;

public class MainGridAdapter extends BaseAdapter {
	private List<FilGridItem> FileData;
	private LayoutInflater inflater;

	public MainGridAdapter(Context context, List<FilGridItem> FileData) {
		this.FileData = FileData;
		inflater = LayoutInflater.from(context);
	}

	public int getCount() {

		return FileData.size();
	}

	@Override
	public FilGridItem getItem(int arg0) {

		return FileData.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		ViewHodler viewHodler;
		if (arg1 == null) {
			viewHodler = new ViewHodler();
			arg1 = inflater.inflate(R.layout.main_grid_item, null);
			viewHodler.itemImageView = (ImageView) arg1
					.findViewById(R.id.item_image);
			viewHodler.itemTextView = (TextView) arg1
					.findViewById(R.id.item_text);
			arg1.setTag(viewHodler);
		} else {
			viewHodler = (ViewHodler) arg1.getTag();
		}
		FilGridItem filGridItem = getItem(arg0);
		arg1.setTag(R.id.item_image,filGridItem);
		viewHodler.itemImageView.setImageResource(filGridItem.icon);
		viewHodler.itemTextView.setText(filGridItem.title);
		return arg1;
	}

	private class ViewHodler {
		private ImageView itemImageView;
		private TextView itemTextView;
	}

}
